package com.example.caoh.common.util;

import java.io.IOException;
import java.util.Properties;

import org.springframework.core.io.support.PropertiesLoaderUtils;

public class Config {

	private static Properties properties;

	private Config() {
	}

	public static void initProperties() {
		try {
			properties = PropertiesLoaderUtils
					.loadAllProperties("config.properties");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static String getConfig(String key) {
		if (null == properties) {
			initProperties();
		}

		String version = properties.get("VERSION").toString().trim()+".";
		if (null != properties.get(key)) {
			if (properties.get(key).toString().trim().startsWith("IP_")) {
				String value = properties.get(key).toString();
				String ipKey = version+value.split("/")[0].toString();
				return value.replace(value.split("/")[0].toString(), properties.get(ipKey).toString());
			}else {
				return properties.get(key).toString();
			}
		}else if(null != properties.get(version+key)){
			return properties.get(version+key).toString();
		}
		return "";
	}
	
	public static void main(String[] args) {
		System.out.println(Config.getConfig(""));
	}
	
}
